﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.OleDb;

public partial class edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int ID = (Request.QueryString["ID"] == null) ? 1 : int.Parse(Request.QueryString["ID"]);
        if (Request.Form["Submit"] == null)
        {
            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\air\Desktop\ASP.net\App_Data\MainDB.mdb;Persist Security Info=True");
            OleDbCommand mycomm = new OleDbCommand("SELECT * FROM [Species] WHERE ID=" + ID, conn);
            conn.Open();
            OleDbDataReader rs = mycomm.ExecuteReader();
            rs.Read();
            ScientificName.Text = rs["ScientificName"];
            ChineseName.Text = rs["ChineseName"];
            CommonName.Text = rs["CommonName"];
            FlowerColor.SelectedValue = rs["FlowerColor"];
            FlowerStyle.SelectedValue = rs["FlowerStyle"];
            FlowerSize.SelectedValue = rs["FlowerSize"];
            LeafStyle.SelectedValue = rs["LeafStyle"];
            Heightr.SelectedValue = rs["Height"];
            PopIntro.Text = rs["PopIntro"];
            rs.Close();
            conn.Close();
        }
        else
        {
            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\air\Desktop\ASP.net\App_Data\MainDB.mdb;Persist Security Info=True");
            OleDbCommand mycomm = new OleDbCommand("UPDATE [Species] SET ScientificName='" + Request.Form["ScientificName"] + "',ChineseName='" + Request.Form["ChineseName"] + "',CommonName='" + Request.Form["CommonName"] + "',FlowerColor=" + Request.Form["FlowerColor"] + ",FlowerStyle=" + Request.Form["FlowerStyle"] + ",FlowerSize=" + Request.Form["FlowerSize"] + ",LeafStyle=" + Request.Form["LeafStyle"] + ",Height=" + Request.Form["Height"] + ",PopIntro= '" + Request.Form["PopIntro"] + "' WHERE ID="+ID, conn);
            conn.Open();
            mycomm.ExecuteNonQuery();
            conn.Close();
            Response.Write("修改成功！");
        }
    }
}
